#include "stdafx.h"
#include <Windows.h>
#include "nt.h"

NTSTATUS NTAPI NewNtQuerySystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, SIZE_T Length, PSIZE_T ResultLength)
{
	static NTSTATUS(NTAPI *pfnNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, SIZE_T, PSIZE_T)
		= (NTSTATUS(NTAPI *)(SYSTEM_INFORMATION_CLASS, PVOID, SIZE_T, PSIZE_T))
		GetProcAddress(GetModuleHandle(L"ntdll.dll"), "NtQuerySystemInformation");

	if (pfnNtQuerySystemInformation)
	{
		return pfnNtQuerySystemInformation(SystemInformationClass, SystemInformation, Length, ResultLength);
	}

	return -1;
}

LPCWSTR WINAPI GetNTStatusCodeString(ULONG status)
{
	switch (status)
	{
	case 0x00000000:return L"STATUS_SUCCESS";

	case 0x80000005:return L"STATUS_BUFFER_OVERFLOW";
	case 0x80000006:return L"STATUS_NO_MORE_FILES";

	case 0x8000000D:return L"STATUS_PARTIAL_COPY";

	case 0x8000001A:return L"STATUS_NO_MORE_ENTRIES";

	case 0xC0000001:return L"STATUS_UNSUCCESSFUL";
	case 0xC0000002:return L"STATUS_NOT_IMPLEMENTED";
	case 0xC0000003:return L"STATUS_INVALID_INFO_CLASS";
	case 0xC0000004:return L"STATUS_INFO_LENGTH_MISMATCH";
	case 0xC0000005:return L"STATUS_ACCESS_VIOLATION";
	case 0xC0000006:return L"STATUS_IN_PAGE_ERROR";
	case 0xC0000007:return L"STATUS_PAGEFILE_QUOTA";
	case 0xC0000008:return L"STATUS_INVALID_HANDLE";
	case 0xC0000009:return L"STATUS_BAD_INITIAL_STACK";
	case 0xC000000A:return L"STATUS_BAD_INITIAL_PC";
	case 0xC000000B:return L"STATUS_INVALID_CID";
	case 0xC000000C:return L"STATUS_TIMER_NOT_CANCELED";
	case 0xC000000D:return L"STATUS_INVALID_PARAMETER";
	case 0xC000000E:return L"STATUS_NO_SUCH_DEVICE";
	case 0xC000000F:return L"STATUS_NO_SUCH_FILE";
	case 0xC0000010:return L"STATUS_INVALID_DEVICE_REQUEST";
	case 0xC0000011:return L"STATUS_END_OF_FILE";
	case 0xC0000012:return L"STATUS_WRONG_VOLUME";
	case 0xC0000013:return L"STATUS_NO_MEDIA_IN_DEVICE";
	case 0xC0000014:return L"STATUS_UNRECOGNIZED_MEDIA";
	case 0xC0000015:return L"STATUS_NONEXISTENT_SECTOR";
	case 0xC0000016:return L"STATUS_MORE_PROCESSING_REQUIRED";
	case 0xC0000017:return L"STATUS_NO_MEMORY";
	case 0xC0000018:return L"STATUS_CONFLICTING_ADDRESSES";
	case 0xC0000019:return L"STATUS_NOT_MAPPED_VIEW";
	case 0xC000001A:return L"STATUS_UNABLE_TO_FREE_VM";
	case 0xC000001B:return L"STATUS_UNABLE_TO_DELETE_SECTION";
	case 0xC000001C:return L"STATUS_INVALID_SYSTEM_SERVICE";
	case 0xC000001D:return L"STATUS_ILLEGAL_INSTRUCTION";
	case 0xC000001E:return L"STATUS_INVALID_LOCK_SEQUENCE";
	case 0xC000001F:return L"STATUS_INVALID_VIEW_SIZE";
	case 0xC0000020:return L"STATUS_INVALID_FILE_FOR_SECTION";
	case 0xC0000021:return L"STATUS_ALREADY_COMMITTED";
	case 0xC0000022:return L"STATUS_ACCESS_DENIED";
	case 0xC0000023:return L"STATUS_BUFFER_TOO_SMALL";
	case 0xC0000030:return L"STATUS_INVALID_PARAMETER_MIX";
	case 0xC0000031:return L"STATUS_INVALID_QUOTA_LOWER";
	case 0xC0000032:return L"STATUS_DISK_CORRUPT_ERROR";
	case 0xC0000033:return L"STATUS_OBJECT_NAME_INVALID";
	case 0xC0000034:return L"STATUS_OBJECT_NAME_NOT_FOUND";
	case 0xC0000035:return L"STATUS_OBJECT_NAME_COLLISION";

	case 0xC0000039:return L"STATUS_OBJECT_PATH_INVALID";	
	case 0xC000003A:return L"STATUS_OBJECT_PATH_NOT_FOUND";
	case 0xC000003B:return L"STATUS_OBJECT_PATH_SYNTAX_BAD";
		
	case 0xC0000043:return L"STATUS_SHARING_VIOLATION";
	case 0xC0000044:return L"STATUS_QUOTA_EXCEEDED";
	case 0xC0000045:return L"STATUS_INVALID_PAGE_PROTECTION";
	case 0xC0000046:return L"STATUS_MUTANT_NOT_OWNED";
	case 0xC0000047:return L"STATUS_SEMAPHORE_LIMIT_EXCEEDED";
	case 0xC0000048:return L"STATUS_PORT_ALREADY_SET";
	case 0xC0000049:return L"STATUS_SECTION_NOT_IMAGE";
	case 0xC000004A:return L"STATUS_SUSPEND_COUNT_EXCEEDED";
	case 0xC000004B:return L"STATUS_THREAD_IS_TERMINATING";

	case 0xC0000061:return L"STATUS_PRIVILEGE_NOT_HELD";

	case 0xC0000096:return L"STATUS_PRIVILEGED_INSTRUCTION";

	case 0xC000009A:return L"STATUS_INSUFFICIENT_RESOURCES";

	case 0xC00000EF:return L"STATUS_INVALID_PARAMETER_1";
	case 0xC00000F0:return L"STATUS_INVALID_PARAMETER_2";
	case 0xC00000F1:return L"STATUS_INVALID_PARAMETER_3";
	case 0xC00000F2:return L"STATUS_INVALID_PARAMETER_4";
	case 0xC00000F3:return L"STATUS_INVALID_PARAMETER_5";

	case 0xC0000106:return L"STATUS_NAME_TOO_LONG";
	}
	return L"Unknown NT Status Code";
}

LPCWSTR WINAPI GetCreateDispositionString(ULONG CreateDisposition)
{
	switch (CreateDisposition)
	{
	case FILE_SUPERSEDE:
		return L"FILE_SUPERSEDE";
	case FILE_OPEN:
		return L"FILE_OPEN";
	case FILE_CREATE:
		return L"FILE_CREATE";
	case FILE_OPEN_IF:
		return L"FILE_OPEN_IF";
	case FILE_OVERWRITE:
		return L"FILE_OVERWRITE";
	case FILE_OVERWRITE_IF:
		return L"FILE_OVERWRITE_IF";
	}
	return L"Unknown CreateDisposition";
}

void WINAPI GetShareAccessString(ULONG ShareAccess, CString &str)
{
	if (ShareAccess & FILE_SHARE_READ)
	{
		if(!str.IsEmpty())
			str.Append(L" | ");
		str.Append(L"FILE_SHARE_READ");
	}
	if (ShareAccess & FILE_SHARE_WRITE)
	{
		if (!str.IsEmpty())
			str.Append(L" | ");
		str.Append(L"FILE_SHARE_WRITE");
	}
	if (ShareAccess & FILE_SHARE_DELETE)
	{
		if (!str.IsEmpty())
			str.Append(L" | ");
		str.Append(L"FILE_SHARE_DELETE");
	}
}